﻿using UnityEngine;
using System.Collections.Generic;
using Dict.DataModel;

namespace UI
{
    public class UIYggdrasilInner : MonoBehaviour
    {
        public UILabel hp;
        public UILabel att;
        public UILabel mdef;
        public UILabel pdef;
        Dictionary<string, float> add = new Dictionary<string, float>(); 
        public void Init()
        {

            List<TableWorldSeed> seeds = new List<TableWorldSeed>();
            
            foreach (var seed in Dict.DictDataManager.Instance.tableWorldSeedDao.CacheList)
            {
                if (int.Parse(seed.id) <= StaticData.playerData.CurrentWorldSeedLevel)
                {
                    seeds.Add(seed);
                }
            }

            add[Dict.Config.TableConst.Hp] = 0;
            add[Dict.Config.TableConst.Attack] = 0;
            add[Dict.Config.TableConst.MagicDefend] = 0;
            add[Dict.Config.TableConst.PhyDefend] = 0;

            foreach (var seed in seeds)
            {
                var strs = seed.get.Split(new char[1] { ',' }, System.StringSplitOptions.RemoveEmptyEntries);
                if (seed.type == 1)
                {
                    add[strs[0]] += float.Parse(strs[1]);
                }
            }
            

            hp.text = "+" + (int)add[Dict.Config.TableConst.Hp] + "";
            att.text = "+" + (int)add[Dict.Config.TableConst.Attack] + "";
            mdef.text = "+" + (int)add[Dict.Config.TableConst.MagicDefend] + "";
            pdef.text = "+" + (int)add[Dict.Config.TableConst.PhyDefend] + "";
        }
    }
}